import request from "./request"

import util from "./util"

import dayjs from './dayjs.min'
const app = getApp()
/**
 * 全局通用分享记录接口
 */
const shareRecord = () => request.creat_share_records({ share: '1', type: '1' })

const listFormat = (arr = [], pageSize = 1) => {
  let newArr = [], tmpArr = [];
  arr.forEach((item, index) => (tmpArr.push(item), (index % pageSize === pageSize - 1 || index === arr.length - 1 ? (newArr.push(tmpArr), tmpArr = []) : null)));
  return newArr;
}
const getWifiInfo = () => {
  return new Promise((resolve, reject) => {
    wx.getConnectedWifi({
      success: (res) => {
        if (res.errMsg !== 'getConnectedWifi:ok') return reject()
        app.globalData.wifiInfo = res?.wifi?.SSID || null
        resolve(res?.wifi?.SSID)
      },
      fail: () => reject()
    })
  })
}


export default { ...request, ...util, shareRecord, dayjs, listFormat, getWifiInfo };